package com.tiany.java_study;

//构造器练习
//定义构造器的格式：权限修饰 类名（形参列表）{}
public class ConstructorTest {
    public static void main(String[] args) {
        Car car = new Car();
        Car car1=new Car("一汽大众");
        //创建类的对象：new + 构造器
        car.setBrand("五菱宏光");
        car.setName("SUV");
        car.setPrice(59999.00);
        System.out.println(car.getBrand());
        System.out.println(car.getName());
        System.out.println(car.getPrice());


    }

}

class Car {
    //属性
    private String name;
    private double price;
    private String brand;

    //构造器
    public Car() {
        System.out.println("This is a constructor");
    }

    public Car(String n){
        name=n;
        System.out.println(name);
    }

    //方法
    public void setBrand(String brand) {
        this.brand = brand;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getPrice() {
        return price;
    }

    public String getBrand() {
        return brand;
    }

    public String getName() {
        return name;
    }
}